package com.heima.apis.article;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.heima.apis.article.fallback.IArticleClientFallback;
import com.heima.model.article.dtos.ArticleCommentDto;
import com.heima.model.article.dtos.ArticleDto;
import com.heima.model.article.pojos.ApArticle;
import com.heima.model.article.pojos.ApArticleConfig;
import com.heima.model.article.vos.ArticleCommnetVo;
import com.heima.model.comment.dtos.CommentConfigDto;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.common.vos.PageResultVo;
import com.heima.model.wemedia.dtos.StatisticsDto;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 文章服务
 */
@FeignClient(
        value = "leadnews-article", // 服务名称
        path = "/api/v1/article", // 接口路径
        fallback = IArticleClientFallback.class) // 降级处理
public interface IArticleClient {

    /**
     * 保存文章
     * @param dto 文章数据
     */
    @PostMapping("/save")
    ResponseResult<Long> saveArticle(@RequestBody ArticleDto dto) ;


    /**
     * 删除文章中引用的图片
     * @param imgUrl 图片url
     */
    @DeleteMapping("/images")
    ResponseResult<String> markImageAsDeleted(@RequestParam("url") String imgUrl)
            throws JsonProcessingException;

    /**
     * 删除文章
     * @param id 文章id
     */
    @DeleteMapping("/{id}")
    void delArticleById(@PathVariable Long id);

    @GetMapping("/queryLikesAndConllections")
    ResponseResult<Map<String, Object>> queryLikesAndConllections(
            @RequestParam("wmUserId") Integer wmUserId,
            @RequestParam("beginDate") Date beginDate,
            @RequestParam("endDate") Date endDate);

    @PostMapping("/newPage")
    PageResultVo<ApArticle> newPage(@RequestBody StatisticsDto dto);

    @GetMapping("/findArticleConfigByArticleId/{articleId}")
    ResponseResult<ApArticleConfig> findArticleConfigByArticleId(@PathVariable("articleId") Long articleId);

    @PostMapping("/findNewsComments")
    PageResponseResult<List<ArticleCommnetVo>> findNewsComments(@RequestBody ArticleCommentDto dto);

    @PostMapping("/updateCommentStatus")
    ResponseResult<AppHttpCodeEnum> updateCommentStatus(@RequestBody CommentConfigDto dto);

}
